// Depends on tencentcloud-sdk-nodejs version 4.0.3 or higher
const tencentcloud = require("tencentcloud-sdk-nodejs");
const config = require("../config");

/* -------------------------------------------------------------------------- */

const BdaClient = tencentcloud.bda.v20200324.Client;

const clientConfig = {
  credential: {
    secretId: config.secretId,
    secretKey: config.secretKey,
  },
  region: "ap-beijing",
  profile: {
    httpProfile: {
      endpoint: "bda.tencentcloudapi.com",
    },
  },
};
const client = new BdaClient(clientConfig);

module.exports = async function (ctx) {
  let imgBase64 = ctx.request.body.imgBase64;
  let age = ctx.request.body.age;
  if (!imgBase64) {
    console.log("没有参数: imgBase64");
    return {
      info: "请上传imgBase64",
    };
  }
  const params = {
    Image: imgBase64,
  };
  let data = await client.DetectBodyJoints(params).then(
    (data) => {
      return data;
    },
    (err) => {
      console.error("error", err);
    }
  );
  return data;
};
